@model LogSearchModel

@{
    //page title
    ViewBag.PageTitle = T("Admin.System.Log").Text;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Log");
}

@{
    const string hideSearchBlockAttributeName = "LogPage.HideSearchBlock";
    var hideSearchBlock = genericAttributeService.GetAttribute<bool>(workContext.CurrentCustomer, hideSearchBlockAttributeName);
}

<form asp-controller="Log" asp-action="List" method="post">
    <div class="content-header clearfix">
        <h1 class="pull-left">
            @T("Admin.System.Log")
        </h1>
        <div class="pull-right">
            <button type="button" id="delete-selected" name="delete-selected" class="btn bg-red">
                <i class="fa fa-trash-o"></i>
                @T("Admin.System.Log.DeleteSelected")
            </button>
            <nop-action-confirmation asp-button-id="delete-selected" />
            <button type="submit" id="clearall" name="clearall" class="btn bg-red">
                <i class="fa fa-trash-o"></i>
                @T("Admin.System.Log.ClearLog")
            </button>
            <nop-action-confirmation asp-button-id="clearall" />
            @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.LogListButtons })
        </div>
    </div>

    <div class="content">
        <div class="form-horizontal">
            <div class="panel-group">
                <div class="panel panel-default panel-search">
                    <div class="panel-body">
                        <div class="row search-row @(!hideSearchBlock ? "opened" : "")" data-hideAttribute="@hideSearchBlockAttributeName">
                            <div class="search-text">@T("Admin.Common.Search")</div>
                            <div class="icon-search"><i class="fa fa-search" aria-hidden="true"></i></div>
                            <div class="icon-collapse"><i class="fa fa-angle-down" aria-hidden="true"></i></div>
                        </div>

                        <div class="search-body @(hideSearchBlock ? "closed" : "")">

                            <div class="row">
                                <div class="col-md-5">
                                    <div class="form-group">
                                        <div class="col-md-4">
                                            <nop-label asp-for="CreatedOnFrom" />
                                        </div>
                                        <div class="col-md-8">
                                            <nop-editor asp-for="CreatedOnFrom" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-md-4">
                                            <nop-label asp-for="CreatedOnTo" />
                                        </div>
                                        <div class="col-md-8">
                                            <nop-editor asp-for="CreatedOnTo" />
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-7">
                                    <div class="form-group">
                                        <div class="col-md-4">
                                            <nop-label asp-for="Message" />
                                        </div>
                                        <div class="col-md-8">
                                            <nop-editor asp-for="Message" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-md-4">
                                            <nop-label asp-for="LogLevelId" />
                                        </div>
                                        <div class="col-md-8">
                                            <nop-select asp-for="LogLevelId" asp-items="Model.AvailableLogLevels" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-7 col-md-offset-5">
                                    <button type="button" id="search-log" class="btn btn-primary btn-search">
                                        <i class="fa fa-search"></i>
                                        @T("Admin.Common.Search")
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="panel panel-default">
                    <div class="panel-body">
                        @await Html.PartialAsync("Table", new DataTablesModel
                        {
                            Name = "log-grid",
                            UrlRead = new DataUrl("LogList", "Log", null),
                            SearchButtonId = "search-log",
                            Length = Model.PageSize,
                            LengthMenu = Model.AvailablePageSizes,
                            Filters = new List<FilterParameter>
                            {
                                new FilterParameter(nameof(Model.CreatedOnFrom)),
                                new FilterParameter(nameof(Model.CreatedOnTo)),
                                new FilterParameter(nameof(Model.Message)),
                                new FilterParameter(nameof(Model.LogLevelId))
                            },
                            ColumnCollection = new List<ColumnProperty>
                            {
                                new ColumnProperty(nameof(LogModel.Id))
                                {
                                    IsMasterCheckBox = true,
                                    Render = new RenderCheckBox("checkbox_log"),
                                    ClassName =  NopColumnClassDefaults.CenterAll,
                                    Width = "50"
                                },
                                new ColumnProperty(nameof(LogModel.LogLevel))
                                {
                                    Title = T("Admin.System.Log.Fields.LogLevel").Text,
                                    Width = "100"
                                },
                                new ColumnProperty(nameof(LogModel.ShortMessage))
                                {
                                    Title = T("Admin.System.Log.Fields.ShortMessage").Text,
                                    Encode = false
                                },
                                new ColumnProperty(nameof(LogModel.CreatedOn))
                                {
                                    Title = T("Admin.System.Log.Fields.CreatedOn").Text,
                                    Width = "200",
                                    Render = new RenderDate()
                                },
                                new ColumnProperty(nameof(LogModel.Id))
                                {
                                    Title = T("Admin.Common.View").Text,
                                    Width = "100",
                                    ClassName =  NopColumnClassDefaults.Button,
                                    Render = new RenderButtonView(new DataUrl("View"))
                                }
                            }
                        })
                        
                        <script>
                            $(document).ready(function() {
                                //"delete selected" button
                                $("#delete-selected-action-confirmation-submit-button").bind("click", function () {
                                    var postData = {
                                        selectedIds: selectedIds
                                    };
                                    addAntiForgeryToken(postData);
                                    $.ajax({
                                        cache: false,
                                        type: "POST",
                                        url: "@(Url.Action("DeleteSelected", "Log"))",
                                        data: postData,
                                        traditional: true,
                                        error: function (jqXHR, textStatus, errorThrown) {
                                            $('#deleteSelectedFailed-info').text(errorThrown);
                                            $("#deleteSelectedFailed").click();
                                        },
                                        complete: function (jqXHR, textStatus) {
                                            updateTable('#log-grid');
                                        }
                                    });
                                    $('#delete-selected-action-confirmation').modal('toggle');
                                    return false;
                                });
                            });
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<nop-alert asp-alert-id="deleteSelectedFailed" />
